package com.beiben.workflow.controller;

import com.beiben.workflow.domain.WfCheckLog;
import com.beiben.workflow.domain.WfCheckLogVo;
import com.beiben.workflow.domain.WorkFlowConstant;
import com.beiben.workflow.service.IWfCheckLogService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 审核日志Controller
 *
 * @author 熊国强
 * @date 2020-12-17
 */
@RestController
@RequestMapping("/workflow/log")
public class WfCheckLogController extends BaseController {
    @Autowired
    private IWfCheckLogService wfCheckLogService;

    /**
     * 查询审核日志列表
     */
    @PreAuthorize("@ss.hasPermi('workflow:log:list')")
    @GetMapping("/list")
    public TableDataInfo list(WfCheckLog wfCheckLog) {
        startPage();
        List<WfCheckLogVo> list = wfCheckLogService.selectWfCheckLogList(wfCheckLog);
        return getDataTable(list);
    }

    /**
     * 导出审核日志列表
     */
    @PreAuthorize("@ss.hasPermi('workflow:log:export')")
    @Log(title = "审核日志", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WfCheckLog wfCheckLog) {
        List<WfCheckLogVo> list = wfCheckLogService.selectWfCheckLogList(wfCheckLog);
        ExcelUtil<WfCheckLogVo> util = new ExcelUtil<WfCheckLogVo>(WfCheckLogVo.class);
        return util.exportExcel(list, "log");
    }

    /**
     * 获取审核日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('workflow:log:query')")
    @GetMapping(value = "/{logId}")
    public AjaxResult getInfo(@PathVariable("logId") Long logId) {
        return AjaxResult.success(wfCheckLogService.selectWfCheckLogById(logId));
    }

    /**
     * 新增审核日志
     */
    @PreAuthorize("@ss.hasPermi('workflow:log:add')")
    @Log(title = "审核日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WfCheckLog wfCheckLog) {
        return toAjax(wfCheckLogService.insertWfCheckLog(wfCheckLog));
    }

    /**
     * 修改审核日志
     */
    @PreAuthorize("@ss.hasPermi('workflow:log:edit')")
    @Log(title = "审核日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WfCheckLog wfCheckLog) {
        return toAjax(wfCheckLogService.updateWfCheckLog(wfCheckLog));
    }

    /**
     * 删除审核日志
     */
    @PreAuthorize("@ss.hasPermi('workflow:log:remove')")
    @Log(title = "审核日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{logIds}")
    public AjaxResult remove(@PathVariable Long[] logIds) {
        return toAjax(wfCheckLogService.deleteWfCheckLogByIds(logIds));
    }


    /**
     * 审批
     *
     * @return
     */
    @Log(title = "审批")
    @PostMapping("/approve")
    public AjaxResult approve(@RequestBody WfCheckLog wfCheck) {

        int result = wfCheckLogService.approve(wfCheck);
        return toAjax(result);
    }

}
